const BaseRest = require('./base.js');
/* 分销系统商户信息 */
module.exports = class extends BaseRest {
  constructor(ctx) {
    super(ctx);
    this.modelInstance = this.model('distribution_merchant');
  }

  /**
   * 获取代理商的信息
   * @return {[type]} [description]
   */
  async getAction() {
    let data;
    const map = {};
    // 获取详情
    if (this.id) {
      map.id = this.get('id');
      const ret = await this.modelInstance.where(map).find();
      if (!think.isEmpty(ret)) {
        data.fenxiao_ratio = ret['fenxiao_ratio'].split(',');
        // ret.fenxiao_ratio.forEach(element => {
        //   element = parseFloat(element);
        // });
        data.levels = data.fenxiao_ratio.length;
        data.sys_royalty_rate = ret['sys_royalty_rate'];
      }
      return this.success(data);
    }
  }
};
